<%-- 
    Document   : Buy
    Created on : 2020-4-19, 10:48:32
    Author     : zhang
--%>

<%@page import="entity.Address"%>
<%@page import="dao.AddressDao"%>
<%@page import="java.util.List"%>
<%@page import="entity.Member"%>
<%@page import="dao.MemberDao"%>
<%@page import="dao.BookDao"%>
<%@page import="entity.Book"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script src="js/jquery-3.4.1.min.js"></script>
        <script>
            $(document).ready(function(){
                $("#btn1").click(function(){
                    $.ajax({
                        url:"compute",
                        type:"GET",
                        data:{
                            count:$("#count").val(),
                        },
                        success:function(data){
                            var price=$("#price").html();
                            $("#spanid").html(data);
                            $("#spanid2").html((data*price).toFixed(2))
                        }
                    })
                })
            })
          
        </script>
        
    </head>
    <body>
        <h1>确认订单</h1>
        <%
            Book book=new BookDao().getBookById(Integer.parseInt(request.getParameter("bookid")));
            
        %>
        <div style="position: absolute;left:500px"><a href="gbbi?id=<%=book.getId()%>">返回</a></div>
        
        <form action="bs?bookid=<%=book.getId()%>" method="post">
            <div>
                <h3><%=book.getBookName()%></h3>
                <div style="width: 200px;height:300px;border:1px solid #000">
                    <img src="img/<%=book.getCover()%>" width="200px" height="300px" alt="<%=book.getBookName()%>">
                </div>
                <div style="width: 300px;height:250px" >
                    <p>编号：<%=book.getId()%></p>
                    <p>作者：<%=book.getAuthor()%></p>
                    <p>数量：<span id="spanid">1</span></p>
                    <p>单价：<span id="price"><%=book.getPrice()%></span></p>
                    <input type="button" value="修改数量" id="btn1">&nbsp;&nbsp;&nbsp;
                    <input type="text" id="count" name="count1" value="1"><br>
                    <a href="gbbi?id=<%=book.getId()%>">查看更多</a>
                </div>
            </div>
            <h1>实付款：<span id="spanid2"><%=book.getPrice()%></span></h1>
            <h3>选择收货地址：</h3><br>
            
            <!--获取未被删除的地址-->
            <%
                Member member=new MemberDao().getMemberByName((String)session.getAttribute("username"));
                List<Address> list=new AddressDao().getAllUndeletedAddress(member.getId());
                for(int i=0;i<list.size();i++){
            %>
            <input type="radio" name="address" value="<%=list.get(i).getId()%>">
            <div>
                详细地址：<%=list.get(i).getAddress()%><br>
                收件人：<%=list.get(i).getAddressee()%><br>
                电话：<%=list.get(i).getPhone()%><br>
                邮编：<%=list.get(i).getZipcode()%>
            </div><br>
            <%
                }
            %>
            <button>支付</button>
        </form>
    </body>
</html>
